﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using TRPOP.CRM.Component.Common;
using TRPOP.CRM.Component.Business;
using TRPOP.CRM.Component.Model;
using TRPOP.Common;

namespace TRPOP.CRM.Web
{
    /// <summary>
    /// 部门列表
    /// </summary>
    public partial class Department_list : BaseAdmin
    {
        #region 权限限制
        protected override void SubPageInit()
        {
            base.m_oCurrentPermissionKey = "Sys_Department";
        }
        #endregion

        #region 页面事件
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindData();
            }
        }

        protected void lbtnDelete_Click(object sender, EventArgs e)
        {
            LinkButton lbtn = (LinkButton)sender;

            //根据departmentID重新获取实体
            DepartmentInfo oDepartmentInfo = DepartmentManage.GetDepartmentById(lbtn.CommandArgument.ToInt());

            if (oDepartmentInfo != null)
            {
                //当前为伪删除
                oDepartmentInfo.bIsDelete = true;
                if (DepartmentManage.SaveDepartment(oDepartmentInfo))
                {
                    Alert("删除成功！");
                }
                else
                {
                    Alert("删除失败!");
                }
            }
            BindData();
        }
        #endregion

        #region 页面方法
        protected void BindData()
        {
            rptList.DataSource = DepartmentManage.GetAllDepartmentTree(0, string.Empty);

            rptList.DataBind();
        }
        #endregion
    }
}